#include <string>
#include <cstring>
#include <errno.h>
#include <libpmem.h>

#include "file.h"
namespace kvalloc {

// PMChunk: mmap a NVM file into virtual memory
class PMChunk {
private:
    void * buf_;
    size_t size_;

public:
    /// @brief If the given file exists, open it and mmap it to virtual memory, if not create one
    /// @param fname NVM file name
    /// @param size  Expected file size, if the file exists, this size should be equal to file size
    PMChunk(const std::string & fname, uint64_t size);

    ~PMChunk();

    // return the mmap memory address: memory is zero-content upon file creation
    void * GetBuf() {return buf_;}

    size_t GetSize() {return size_;}
};

} // namespace kvalloc